package com.ara.common.kernel.util;

import android.content.Context;

/**
 * Created by XieXin on 2018/12/10.
 * 尺寸相关工具类
 */
public class SizeUtils {
    private SizeUtils() {
    }

    /**
     * dp转px
     *
     * @param dpValue dp值
     * @return px值
     */
    public static int dp2px(Context context, Float dpValue) {
        Float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * px转dp
     *
     * @param dpValue dp值
     * @return px值
     */
    public static int px2dp(Context context, Float dpValue) {
        Float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue / scale + 0.5f);
    }

    /**
     * sp转px
     *
     * @param spValue sp值
     * @return px值
     */
    public static int sp2px(Context context, Float spValue) {
        Float scale = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (spValue * scale + 0.5f);
    }

    /**
     * px转sp
     *
     * @param pxValue px值
     * @return px值
     */
    public static int px2sp(Context context, Float pxValue) {
        Float scale = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (pxValue / scale + 0.5f);
    }
}
